<?php
require_once 'libraries/utilities/function.php';
$path = '../ptnhuan-web1/data/films.txt';
$full_path = realpath($path); // tra ve duong dan
$films = mreadFile($path); //doc File
$rating1 = NULL;
$rating2 = NULL;
?>
<form method="POST">
    FROM <input type="text" name="rating1">
    TO<input type="text" name="rating2">
    <input type="submit" name="submit" value="Go">
</form>


<?php if (isset($_POST['submit'])): ?>
    <?php $rating1 = (double) $_POST['rating1']; ?>
    <?php $rating2 = (double) $_POST['rating2']; ?>
<?php endif; ?>
<?php foreach ($films as $item): ?>
    <?php
    $item = trim($item);
    if (!empty($item)):
        ?>
        <?php
        $film = explode(";", $item);
        $img = trim($film[1]);
        ?>
        <?php if (empty($rating1) && empty($rating2)): ?>
            <?php if (isset($film[2]) || (isset($film[3]))): ?> 
                <a href='file_edit.php?if= <?php echo "$film[0]"; ?>'>EDIT</a>
                <img src = '../ptnhuan-web1/public/images/films/<?php echo $img ?>'> 
                <?php echo $film[2] ?>
                <?php echo $film[3] ?>
                <br>
            <?php endif; ?>
        <?php else: ?>
            <?php if (isset($film[2]) || isset($film[3])): ?>
                <?php if (($rating1 <= (double) $film[3]) && ($rating2 >= (double) $film[3])): ?> 
                 <a href='file_edit.php?if= <?php echo "$film[0]"; ?>'>EDIT</a>
                    <img src = '../ptnhuan-web1/public/images/films/<?php echo $img ?>'>             
                    <?php echo $film[2] ?>
                    <?php if (!empty($film[3])) echo $film[3] ?>
                    <br>
                <?php endif; ?>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
<?php endforeach; ?>   